<template>
  <div id="activeTopSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="搜索：">
          <el-input
            v-model="formInline.dpAccount"
            placeholder="请输入大鹏号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="活动名称：">
          <el-select v-model="formInline.activityId" placeholder="请输入活动名称">
            <el-option
              v-for="item in activityAll"
              :key="item.activityId"
              :label="item.activityName"
              :value="item.activityId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="时间：">
          <el-date-picker
            style="width:400px"
            v-model="formInline.time"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch(formInline.activityId)">
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>

export default {
  watch: {
    'formInline.time': {
      immediate: true,
      handler(newV, oldV) {
        if (newV == null) {
          this.formInline.startFlowTime = ''
          this.formInline.endFlowTime = ''
        } else {
          this.formInline.startFlowTime = newV[0]
          this.formInline.endFlowTime = newV[1]
        }
      },
      deep: true
    }
  },
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
        activityId: '', //活动id
        dpAccount: '', // 大鹏号 or 手机号
        startFlowTime: '', // 开始时间
        endFlowTime: '', // 结束时间
        time: []
        }
      }
    },
    activityAll:{
      type: Array,
      default: ''
    }
  },
  data() {
    return {
      time: [],
      // 状态
      statusOption: [
        {
          value: '',
          label: '全部'
        },
        {
          value: 'NO',
          label: '未开始'
        },
        {
          value: 'YES',
          label: '进行中'
        },
        {
          value: 'NOO',
          label: '已结束'
        },
      ],
      // 活动名称
      activityOptions: [
        {
          value: '0',
          label: '邀请一期'
        },
        {
          value: '1',
          label: '邀请二期'
        },
      ],
      activityId: ''
    }
  },
  created(){

  },
  mounted() {
  },
  methods: {
    toSearch(activityId) {
      this.activityId = activityId
      this.$emit('toSearch', activityId)
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      this.setDefaultValue()
    },
    setDefaultValue() {
      this.formInline.activityId = this.activityAll[0].activityId
      this.formInline.dpAccount = ''
      this.formInline.time = ''
      this.formInline.startFlowTime = ''
      this.formInline.endFlowTime = ''
    }
  }
}
</script>

<style lang="less" scoped>
:deep(.search-box) {
  margin-bottom: 0px !important;
}
.search-box :deep(.el-input__inner) {
  padding: 0 30px;
}
:deep(.s-btn) {
  margin-left: 10px !important;
}
</style>
